package com.liugl.uiwidgettest

import android.app.Activity

object ActivityController {
    private val activityList = ArrayList<Activity>()

    ///添加一个新的Activity
    fun addActivity(activity: Activity) {
        activityList.add(activity)
    }

    //移除一个Activity
    fun removeActivity(activity: Activity) {
        activityList.remove(activity)
    }

    //退出程序
    fun finishAll() {
        //遍历并结束所有Activity
        for (activity in activityList) {
            if (!activity.isFinishing) {
                activity.finish()
            }
        }

        //清空Activity列表
        activityList.clear()
        //杀掉当前进程
        android.os.Process.killProcess(android.os.Process.myPid())
    }
}